import axios from "axios";
import router from "@/router";

import {Notification} from "element-ui";

//创建axios实例
const huige = axios.create({
    baseURL: 'http://localhost:10086/',
    timeout: 10000,
});

//设置拦截器
huige.interceptors.request.use(function (config) {
    var item = localStorage.getItem("token");
    config.headers.Authentication = "Bearer " + item
    return config;
}, function (error) {
    return Promise.reject(error);
});

huige.interceptors.response.use(function (response) {
    let {status, message, data} = response.data;
    if (status == 20000) {
        return data;
    } else if (status == 44444) {
        router.push("/login")
    } else {
        //错误信息
        Notification.error(message);
        return Promise.reject(new Error(message));
    }
}, function (error) {
    return Promise.reject(error);
});


export default huige;
